package com.wdog5.tutorial;

import org.bukkit.Material;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Firework;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.inventory.ItemStack;

public class EventListener implements Listener {

    @EventHandler
    public static void loggedIn(PlayerLoginEvent event) {
        var player = event.getPlayer();
        if (player.getName().equals("wdog5")) {
            player.getWorld().createEntity(player.getLocation(), Firework.class);
        }
    }

    @EventHandler
    public static void onEntityDeath(EntityDeathEvent event) {
        var entity = event.getEntity();
        var type = event.getEntityType();
        var damageSource = event.getDamageSource();
        var dropsItem = event.getDrops();
        var exp = event.getDroppedExp();
        if (entity instanceof Cow) {
            dropsItem.add(new ItemStack(Material.BONE));
            int oldExp = exp;
            int newExp = oldExp + 10.0;
            exp = newExp;
        }
    }
}
